package com.ruoyi.web.controller.constructionLike;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.constructionLike.ConstructionRemark;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.domain.vo.ConstructionCustomerVo;
import com.ruoyi.system.service.constructionLike.ConstructionRemarkService;
import com.ruoyi.system.utils.TokenUtils;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 施工攻略Controller
 *
 * @author gxj
 * @date 2021-04-11
 */
@RestController
@RequestMapping("/api/system/remark")
public class ConstructionRemarkController extends BaseController {
    @Autowired
    private ConstructionRemarkService constructionRemarkService;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private HttpServletRequest request;

    /**
     * 查询施工攻略列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ConstructionCustomerVo constructionRemark)
    {
        startPage();
        List<ConstructionCustomerVo> list = constructionRemarkService.selectConstructionRemarkList(constructionRemark);
        return getDataTable(list);
    }

    @GetMapping("/findAllList/{constructionStrategyId}")
    public List<ConstructionCustomerVo> findAllList(@PathVariable("constructionStrategyId") Integer constructionStrategyId){
        ConstructionCustomerVo constructionCustomerVo = new ConstructionCustomerVo();
        constructionCustomerVo.setConstructionStrategyId(constructionStrategyId);
        List<ConstructionCustomerVo> allList = constructionRemarkService.findAllList(constructionCustomerVo);
        return allList;
    }
    /**
     * 导出施工攻略列表
     */
    @Log(title = "施工攻略", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConstructionCustomerVo constructionRemark)
    {
        List<ConstructionCustomerVo> list = constructionRemarkService.selectConstructionRemarkList(constructionRemark);
        ExcelUtil<ConstructionCustomerVo> util = new ExcelUtil<ConstructionCustomerVo>(ConstructionCustomerVo.class);
        return util.exportExcel(list, "remark");
    }

    /**
     * 获取施工攻略详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(constructionRemarkService.selectConstructionRemarkById(id));
    }

    /**
     * 新增施工攻略
     */
    @Log(title = "施工攻略", businessType = BusinessType.INSERT)
    @PostMapping("/addRemark")
    public AjaxResult add(@RequestBody ConstructionRemark constructionRemark)
    {
        CustomerLogin loginCustomer = tokenUtils.getLoginCustomer(request);
        Long customerId = loginCustomer.getCustomerId();
        constructionRemark.setUserId(Math.toIntExact(customerId));
        return toAjax(constructionRemarkService.insertConstructionRemark(constructionRemark));
    }

    /**
     * 修改施工攻略
     */
    @Log(title = "施工攻略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionRemark constructionRemark)
    {
        return toAjax(constructionRemarkService.updateConstructionRemark(constructionRemark));
    }

    /**
     * 删除施工攻略
     */
    @Log(title = "施工攻略", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(constructionRemarkService.deleteConstructionRemarkByIds(ids));
    }
}
